package dongze.com.ckdj.databinding.model;

import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.databinding.ObservableField;
import android.view.View;
import android.widget.DatePicker;
import android.widget.TimePicker;

import java.util.Calendar;
import java.util.Date;

import dongze.com.ckdj.activity.ParkLotQueryActivity;

/**
 * Created by fanqwz on 2017/11/30.
 */

public class ParkingLotQueryModel {
    ParkLotQueryActivity activity;
    public ObservableField<Date> from = new ObservableField<>(new Date());
    public ObservableField<Date> to = new ObservableField<>(new Date());
    public ObservableField<String[]> brands = new ObservableField<>(new String[]{""});
    public ObservableField<Integer> brandPos = new ObservableField<>(0);
    public ObservableField<String> count = new ObservableField<>("0");
    public ObservableField<String[]> voyage = new ObservableField<>(new String[]{""});
    public ObservableField<Integer> voyagePos = new ObservableField<>(0);

    public ParkingLotQueryModel(ParkLotQueryActivity activity) {
        this.activity = activity;
        Calendar cal = Calendar.getInstance();
        cal.setTime(from.get());
        cal.add(Calendar.DATE, -1);
        from.set(cal.getTime());
    }

    public void changeFromDate(View view) {
        new DatePickerDialog(view.getContext(), AlertDialog.THEME_HOLO_LIGHT, new DatePickerDialog.OnDateSetListener() {
            @Override
            public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
                from.get().setYear(year - 1900);
                from.get().setMonth(month);
                from.get().setDate(dayOfMonth);
                from.notifyChange();
            }
        }, from.get().getYear() + 1900, from.get().getMonth(), from.get().getDate())
                .show();
    }

    public void changeFromTime(View view) {
        new TimePickerDialog(view.getContext(), AlertDialog.THEME_HOLO_LIGHT, new TimePickerDialog.OnTimeSetListener() {
            @Override
            public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                from.get().setHours(hourOfDay);
                from.get().setMinutes(minute);
                from.notifyChange();
            }

        }, from.get().getHours(), from.get().getMinutes(), true)
                .show();
    }

    public void changeToDate(View view) {
        new DatePickerDialog(view.getContext(), AlertDialog.THEME_HOLO_LIGHT, new DatePickerDialog.OnDateSetListener() {
            @Override
            public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
                to.get().setYear(year - 1900);
                to.get().setMonth(month);
                to.get().setDate(dayOfMonth);
                to.notifyChange();
            }
        }, to.get().getYear() + 1900, to.get().getMonth(), to.get().getDate())
                .show();
    }

    public void changeToTime(View view) {
        new TimePickerDialog(view.getContext(), AlertDialog.THEME_HOLO_LIGHT, new TimePickerDialog.OnTimeSetListener() {
            @Override
            public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                to.get().setHours(hourOfDay);
                to.get().setMinutes(minute);
                to.notifyChange();
            }

        }, to.get().getHours(), to.get().getMinutes(), true)
                .show();

    }

    public void query(View view) {
        activity.onQuery();
    }

    public void reset(View view) {
        activity.onReset();
    }
}
